package cn.marinda.entity;

import cn.marinda.MinecraftServerHelper;
import cn.marinda.runnable.DownloadServerPluginRunnable;
import cn.marinda.util.ThreadUtils;
import lombok.Data;

import javax.swing.*;

/**
 * 文摘服务器插件
 *
 * @author admin
 * @date 2022/07/14
 */
@Data
public abstract class AbstractServerPlugin extends AbstractServerResource{

    /**
     * 核心文件名称
     */
    protected String fileName;
    //    接入Core下载地址
    protected final String PLUGIN_PATH = "mcPlugin/";
    protected Server serverDir = Server.SERVER_DOWNLOAD_PLUGIN;
    //    基础插件
    public static String[] pluginList = new String[]{
            "[基础插件]EssentialsX","[经济前置]Vault","[基础插件]EssentialsXChat","[基础插件]EssentialsXGeoIP","[基础插件]EssentialsXSpawn",
            "[基础插件]EssentialsXXMPP","[基础插件]EssentialsXXMPP","[变量API]PlaceholderAPI","[权限组]GroupManager"
    };

    public AbstractServerPlugin(){

    }

    /**
     * 服务器插件
     *
     * @param fileName 文件名称
     */
    public AbstractServerPlugin(String fileName){
        super(fileName);
    }



    @Override
    public void download(JProgressBar progressBar) {
        String pluginPath = URL_PATH + PLUGIN_PATH;
        Server serverEnum = serverDir;
                //        等于下载地址+核心名.jar
        DownloadServerPluginRunnable pluginRunnable = new DownloadServerPluginRunnable(progressBar,serverEnum,pluginPath);
        ThreadUtils.downloadPluginScheduled = MinecraftServerHelper.executorService.submit(pluginRunnable);
    }

    @Override
    protected String[] resourceList() {
        return pluginList;
    }

    @Override
    protected Server serverDir() {
        return  serverDir;
    }
}
